﻿# encoding:utf-8
# 访问数据库 配置表
from wxpyImport import *
from db.wxpyDbBase import *

# 根据 key 取值
def dbGetConfig(dbd, key):
    sql = "select * from config where `key` = %s order by create_time desc"

    try:
        cursor = getCursorColName(dbd)
        cursor.execute(sql,(key))
        results = cursor.fetchone()
        cursor.close()
        if len(results)<1:
            return None

        return results['value']
    except Exception as e:
        dealException()
        logError('dbGetConfi err: '+str(e))
    
    return None

# 判断是否存在这样一组 key + value
def dbConfigExist(dbd, key, value):
    sql = "select id from config where `key`=%s and value=%s"

    try:
        cursor = getCursor(dbd)
        cursor.execute(sql,(key, value))
        results = cursor.fetchone()
        cursor.close()
        if results is None:
            return False
            
        return len(results)>0
    except Exception as e:
        dealException()
        logError('dbConfigExis err: '+str(e))
    
    return False